import DictionaryConstants from "@/const/DictionaryConstants.ts";
import instance from "@/api/request.ts";
import { UserLoginVo } from "@/model/LoginModel.ts";

const ApiConst = DictionaryConstants.ApiConst;
/**
 * 用户根据账号密码登陆
 * @param userName 账号
 * @param password 密码
 * @return  UserLoginVo
 */
const userLoginByUsernameAndPassword = (userName: string, password: string) => {
    return instance.get(`${ApiConst.AUTH}/login/password-and-username`, {
        params: {
            userName,
            password,
        },
        headers: {
            "IS_SHOW_NOTIFICATION": DictionaryConstants.AxiosConfigConst.IS_SHOW_NOTIFICATION.FALSE.value,
            "IS_ADD_TOKEN": DictionaryConstants.AxiosConfigConst.IS_ADD_TOKEN.FALSE.value,
        },
    });
};
/**
 * 用户根据code登陆
 * @param code gitee请求码
 */
const userLoginByGitee: UserLoginVo = (code: string) => {
    return instance.get(`${ApiConst.AUTH}/login/gitee`, {
        params: {
            code,
        },
        headers: {
            "IS_SHOW_NOTIFICATION": DictionaryConstants.AxiosConfigConst.IS_SHOW_NOTIFICATION.FALSE.value,
            "IS_ADD_TOKEN": DictionaryConstants.AxiosConfigConst.IS_ADD_TOKEN.FALSE.value,
        },
    });
};

export const LoginApi = {
    userLoginByUsernameAndPassword,
    userLoginByGitee,
};